home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
res
/
blog
/
selfBlog
/
index.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
38KB
|
837 lines
<?php
/**
* SelfBlog main file
*
* Display, edit, modify and save blog
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 1.0.0
*/
/*
* File map :
* functions getMinMaxDate
* generateID
* getTimeStamp
* getCommentsList
* getMessagesList
*
* INIT BLOG DATA (once)
* Load messages XML file (or create it)
* PROCESS POST PARAMETERS
* Insert HEAD, FORMS and JAVASCRIPT functions
* DISPLAY BLOG
* Messages and comments
* Profile section
* History
*
*/
require_once(INCLUDE_DIR.'outputFunctions.php');
/**
* @return array 'min' & 'max' timestamp
* @desc return an array containing min and max timestamp of messages
*/
function getMinMaxDate(){
global $root;
foreach ($root->getElementsByTagName('message') as $node){
if($node->hasAttribute('ID') && $node->hasAttribute('date') && $ts=getTimeStamp($node->getAttribute('date'))){
if((!isset($min)) || $min>$ts) $min=$ts;
if((!isset($max)) || $max<$ts) $max=$ts;
}
}
if(!isset($min)) return false; else return array('min' => $min, 'max' => $max);
}
/**
* @return int ID
* @desc browse $dom for max ID found and return max ID +1 . Used to generate an unused ID for a new message or comment
*/
function generateID(){
global $root;
$maxID=0;
foreach ($root->getElementsByTagName('message') as $node){
if($node->hasAttribute('ID') && is_numeric($node->getAttribute('ID')) && $node->getAttribute('ID')>$maxID) $maxID=$node->getAttribute('ID');
}
foreach ($root->getElementsByTagName('comment') as $node){
if($node->hasAttribute('ID') && is_numeric($node->getAttribute('ID')) && $node->getAttribute('ID')>$maxID) $maxID=$node->getAttribute('ID');
}
return $maxID+1;
}
/**
* @return long timestamp
* @param string $formated date
* @desc return time stamp from 'Y/m/d-H:i:s' formated date
*/
function getTimeStamp($strDate){
if(strlen($strDate)!=19) return false;
return mktime(substr($strDate,11,2), substr($strDate,14,2), substr($strDate,17,2), substr($strDate,5,2), substr($strDate,8,2), substr($strDate,0,4));
}
/**
* @return array : sorted array of comments, including for each comment :
* string ID : id of comment
* string body : body of comment
* @param domNode : $message
* @desc return an array of
*/
function getCommentsList($messageNode){
$commentsArray=array();
$comments=$messageNode->getElementsByTagname('comment');
if($comments) foreach ($comments as $comment){
if($comment->hasAttribute('date') && $comment->hasAttribute('ID')){
// date
$timeStamp=getTimeStamp($comment->getAttribute('date'));
// ID
$commentsArray[$timeStamp]['ID']=$comment->getAttribute('ID');
// IP
if($comment->hasAttribute('IP')) $commentsArray[$timeStamp]['IP']=$comment->getAttribute('IP');
// e-mail
if($comment->hasAttribute('eMail')) $commentsArray[$timeStamp]['eMail']=$comment->getAttribute('eMail');
// web link
if($comment->hasAttribute('link')) $commentsArray[$timeStamp]['link']=$comment->getAttribute('link');
// author
$commentsArray[$timeStamp]['author']=$comment->getElementsByTagname('author')->item(0)->nodeValue;
// comment body
$commentsArray[$timeStamp]['body']=$comment->getElementsByTagname('body')->item(0)->nodeValue;
// whole comment node
$commentsArray[$timeStamp]['node']=$comment;
}
}
ksort($commentsArray);
return $commentsArray;
}
/**
* @return array : array of DomElement
* @param long $dateFrom : timestamp of date from which message are included
* @param long $dateTo : timestamp of date up to which message are included
* @desc return an array of domNodes of messages included between dateFrom and dateTo, and sort by inverse date
*/
function getMessagesList($dateTo=false, $dateFrom=false){
global $dom;
$messagesArray=array();
$messages=$dom->getElementsByTagName("message");
foreach ($messages as $message){
if($message->getAttribute('ID') && $message->getAttribute('date')){
if($timeStamp=getTimeStamp($message->getAttribute('date'))){
if((!$dateTo) || (!$dateFrom && $timeStamp<=$dateTo) || ($timeStamp<=$dateTo && $timeStamp>=$dateFrom))
$messagesArray[$timeStamp]=$message;
}
}
}
krsort($messagesArray);
return $messagesArray;
}
/**
* @return bool : true if message found
* @param long $dateFrom : timestamp of lower bound of interval
* @param long $dateTo : timestamp of higher bound of interval
* @desc return true if a message has been posted between dateFrom and dateTo
*/
function messageInInterval($dateTo, $dateFrom){
global $allMessages;
foreach ($allMessages as $key=>$value) if($key<=$dateTo && $key>=$dateFrom) return true;
return false;
}
/*
***************************************************************************************************************************
* Init blog data
***************************************************************************************************************************
*/
if(!cfRGetVar('parametersLoaded')){
// Set default values for unset variables (which are theoricaly present in resource config file)
if(!(cfRGetVar('commentsAllowed'))) cfRSetVar('commentsAllowed',false);
if(cfRGetVar('commentsAllowed')) cfRSetVar('displayComments',true);
if(!(cfRGetVar('maxPostPerPage'))) cfRSetVar('maxPostPerPage',5);
if(!(cfRGetVar('useProfile'))) cfRSetVar('useProfile',false);
if(!(cfRGetVar('profileName'))) cfRSetVar('profileName','');
if(!(cfRGetVar('profileEMail'))) cfRSetVar('profileEMail','');
if(!(cfRGetVar('profileComment'))) cfRSetVar('profileComment','');
if(!(cfRGetVar('userTempDirAccessAllowed'))) cfRSetVar('userTempDirAccessAllowed',false);
if(!(cfRGetVar('resourceDataDirAccessAllowed'))) cfRSetVar('resourceDataDirAccessAllowed',true);
cfRSetVar('fileTypeFilter',array('image')); // Set uploaded files extension filter
if(cfRGetVar('unfoldPosts')===false) cfRSetVar('unfoldPosts',true);
if(!isset($criticalErrorMessage)) cfRSetVar('parametersLoaded',true);
}
$dom = new DOMDocument('1.0', 'utf-8');
// Init / set dates
if(!cfRGetVar('dateFrom')) cfRSetVar('dateFrom', false);
if(!cfRGetVar('dateTo')) cfRSetVar('dateTo', mktime());
$dateFrom=cfRGetVar('dateFrom');
$dateTo=cfRGetVar('dateTo');
// Load XML messages file
if(file_exists(cfAppResourceDir().'/blogMessages.xml')){
;
if(!(@$dom->load(cfAppResourceDir().'/blogMessages.xml'))) {
$criticalErrorMessage=cfCaption('blogErrorFileIncorrect');
cfLog('Error : blog message file "'.cfAppResourceDir().'/blogMessages.xml'.'" couldn\'t be parsed',LOG_ER);
}
else $root=$dom->documentElement;
}
// If XML messages file doesn't exist, create it
else{
$dom->loadXML('<?xml version="1.0" encoding="UTF-8"?><blog/>');
if(!($dom->save(cfAppResourceDir().'/blogMessages.xml'))){
$criticalErrorMessage=cfCaption('blogErrorCannotSaveFile');
cfLog('Error : blog message file "'.cfAppResourceDir().'/blogMessages.xml'.'" couldn\'t be created',LOG_ER);
}
$root=$dom->documentElement;
}
/*
***************************************************************************************************************************
* Process POST commands
***************************************************************************************************************************
*/
if(!isset($criticalErrorMessage)){
// Process hide / show all posts
cfAsyncXMLChangePhpVarValue('unfoldPosts');
// Change comments hide / show value from async request
cfAsyncXMLChangePhpVarValue('displayComments');
$saveXMLFileRequired=false;
// New message
if(isset($_POST['newMessageBody']) && cfUGetVar('administrator')){
// Generate and Append new node
$newMessageNode=$dom->createElement('message');
$newMessageNode->setAttribute('ID', generateID());
$newMessageNode->setAttribute('date', date('Y/m/d-H:i:s'));
// Message title
if(isset($_POST['newMessageTitle'])) {
$newMessageNode->appendChild($dom->createElement('title',cfXMLEncode(cfUTF8Decode($_POST['newMessageTitle'],false,true,true,64))));
}
// Image
if(cfRGetVar('uploadedImage') && cfRGetVar('uploadedImagePosition')){
if(file_exists(cfAppResourceDir().'/tmpImg.jpg')){
$i=0;
while (file_exists(cfAppResourceDir().'/'.$i.'.jpg')) $i++;
rename(cfAppResourceDir().'/tmpImg.jpg', cfAppResourceDir().'/'.$i.'.jpg');
$imageNode=$dom->createElement('image');
$imageNode->setAttribute('fileName', $i.'.jpg');
$imageNode->setAttribute('position', cfRGetVar('uploadedImagePosition'));
$newMessageNode->appendChild($imageNode);
}
}
// Message body
$_POST['newMessageBody']=str_replace("\r",'<br />',str_replace("\n",'<br />',str_replace("\r\n",'<br />',$_POST['newMessageBody'])));
$newMessageNode->appendChild($dom->createElement('body',cfXMLEncode(cfUTF8Decode($_POST['newMessageBody'],false,true,false,4096))));
// set position on new message
$dateTo=getTimeStamp($newMessageNode->getAttribute('date'));
$dateFrom=false;
$saveXMLFileRequired=true;
$root->appendChild($newMessageNode);
}
// Commands sent via action / value form (edit, delete / next / previous /...)
if(isset($_POST['action']) && isset($_POST['value'])){
// Delete message or comment
if($_POST['action']=='delete' && cfUGetVar('administrator')){
// Browse comments
foreach ($root->getElementsByTagName('comment') as $node){
if($node->getAttribute('ID')==$_POST['value']){
$node->parentNode->removeChild($node);
$saveXMLFileRequired=true;
break;
}
}
// Browse messages to find the one with matching Id
foreach ($root->getElementsByTagName('message') as $node){
if($node->getAttribute('ID')==$_POST['value']){
// remove image from disk
if($node->getElementsByTagName('image')->length>0)
@unlink(cfAppResourceDir().'/'.$node->getElementsByTagName('image')->item(0)->getAttribute('fileName'));
$node->parentNode->removeChild($node);
$saveXMLFileRequired=true;
break;
}
}
}
// Delete message or comment
elseif($_POST['action']=='edit' && cfUGetVar('administrator')){
// Browse messages to find the one with matching Id
foreach ($root->getElementsByTagName('message') as $node){
if($node->getAttribute('ID')==$_POST['value']){
$_POST['value2']=str_replace("\r",'<br />',str_replace("\n",'<br />',str_replace("\r\n",'<br />',$_POST['value2'])));
// Edit date
if($node->hasAttribute('editDate')) $node->removeAttribute('editDate');
$node->setAttribute('editDate', time());
// Set new title
foreach ($node->childNodes as $subNode) if($subNode->nodeName=='title') $subNode->nodeValue=cfXMLEncode(cfUTF8Decode($_POST['value3'],false,true,false,4096));
// Set new body
foreach ($node->childNodes as $subNode) if($subNode->nodeName=='body') $subNode->nodeValue=cfXMLEncode(cfUTF8Decode($_POST['value2'],false,true,false,4096));
$saveXMLFileRequired=true;
break;
}
}
}
// show previous / next messages
elseif($_POST['action']=='prevNext' && is_numeric($_POST['value'])){
$dateFrom=false;
$dateTo=$_POST['value'];
}
// show messages included in given period
if($_POST['action']=='period' && isset($_POST['value2']) && is_numeric($_POST['value'])&& is_numeric($_POST['value2'])){
$dateFrom=$_POST['value'];
$dateTo=$_POST['value2'];
}
// show messages included in given period
if($_POST['action']=='resetDate'){
$dateFrom=false;
$dateTo=mktime();
}
}
// New comment
if(isset($_POST['newCommentAuthor']) && isset($_POST['newCommentBody']) && isset($_POST['messageID']) && cfRGetVar('commentsAllowed')){
foreach (getMessagesList(false,false) as $node){
if($node->getAttribute('ID')==$_POST['messageID']) {
$newCommentNode=$dom->createElement('comment');
$newCommentNode->setAttribute('ID', generateID());
$newCommentNode->setAttribute('date', date('Y/m/d-H:i:s'));
$newCommentNode->setAttribute('IP', $_SESSION['accountIP']);
if(isset($_POST['newCommentEMail'])) $newCommentNode->setAttribute('eMail', cfXMLEncode(cfUTF8Decode($_POST['newCommentEMail'],false,true,true,64)));
if(isset($_POST['newCommentLink'])) $newCommentNode->setAttribute('link', cfXMLEncode(cfUTF8Decode($_POST['newCommentLink'],false,true,true,64)));
// Author
$newCommentNode->appendChild($dom->createElement('author',cfXMLEncode(cfUTF8Decode($_POST['newCommentAuthor'],false,true,true,64))));
// Comment body
$newCommentNode->appendChild($dom->createElement('body',cfXMLEncode(cfUTF8Decode($_POST['newCommentBody'],false,true,true,2048))));
// Append to message node
$node->appendChild($newCommentNode);
$saveXMLFileRequired=true;
}
}
}
//Save XML file
if($saveXMLFileRequired && !($dom->save(cfAppResourceDir().'/blogMessages.xml'))){
$criticalErrorMessage=cfCaption('blogErrorCannotSaveFile');
cfLog('Error : blog message file "'.cfAppResourceDir().'/blogMessages.xml'.'" couldn\'t be created',LOG_ER);
}
// Memorize position
cfRSetVar('dateFrom',$dateFrom);
cfRSetVar('dateTo', $dateTo);
}
/**
* Mobiles
*/
if(cfIsMobile()) {require(dirname($_SERVER['SCRIPT_FILENAME']).'/mobileIndex.php');exit;}
/*
***************************************************************************************************************************
* Insert HEAD, FORMS and JAVASCRIPT functions
***************************************************************************************************************************
*/
if(isset($criticalErrorMessage)) outDisplayErrorPage($criticalErrorMessage); // If a critical error has been raised, display error page and exit
// Get message list
$messages=getMessagesList($dateTo, $dateFrom);
if(count($messages)) $minMax=getMinMaxDate(); else $minMax=false; // get date (timestamp) of 1st and last message
cfInsertHEAD(false);
?>
<script language="javascript" type="text/javascript">
var uploadInProgress;
var commentsDisplay=<?php if(cfRGetVar('displayComments')) echo '1'; else echo '0';?>;
function showNewMsg(){
dgi("newPostForm").style.display="block";
dgi("newPostButton").style.display="none";
}
function hideNewMsg(){
dgi("newPostForm").style.display="none";
dgi("newPostButton").style.display="block";
}
function sendNewMessage(){
if(uploadInProgress) alert('<?echo cfCaptionJS('genSendInProgress')."'+String.fromCharCode(13)+'".cfCaptionJS('genWait');?>');
else {
dgi('uploadResult').innerHTML='<?php echo cfCaption('genWait');?>';
if(W.winUseWindows && D.newMessage.target=="") winMe.setReloading();
D.newMessage.submit();
}
}
function uploadCompleted(result){
if(result) dgi('uploadResult').innerHTML='<?php echo cfCaption('blogImageSent');?>';
else dgi('uploadResult').innerHTML='<?php echo cfCaption('blogNoImageSent');?>';
uploadInProgress=false;
}
function deleteMsg(id){
if(confirm("<?php echo cfCaption('blogConfirmDelete');?>")){
dgi("action").value='delete';
dgi("value").value=id;
if(W.winUseWindows && document.forms.miscAction.target=="") winMe.setReloading();
document.forms['miscAction'].submit();
}
}
function saveEditMsg(id){
dgi("action").value='edit';
dgi("value").value=id;
dgi("value2").value=dgi("messageEdit"+id).value;
dgi("value3").value=dgi("messageEditTitle"+id).value;
if(window.winUseWindows && document.forms.miscAction.target=="") winMe.setReloading();
document.forms['miscAction'].submit();
}
function editMsg(id,focus){
if(dgi("messageEdit"+id)) return;
//Bt
dgi("supprBt"+id).style.display="none";
dgi("saveBt"+id).style.display="inline";
// Body
var h=dgi("message"+id).offsetHeight;
var ih=dgi("message"+id).innerHTML.replace(/<BR\/>/gi,String.fromCharCode(13)).replace(/<BR>/gi,String.fromCharCode(13));
dgi("message"+id).innerHTML='<textarea style="width:100%;" rows="5" id="messageEdit'+id+'">'+ih+'</textarea>';
while(dgi("messageEdit"+id).offsetHeight<h && dgi("messageEdit"+id).rows<15) dgi("messageEdit"+id).rows++;
// Title
h=dgi("messageT"+id).offsetWidth;
ih=dgi("messageT"+id).innerHTML;
dgi("messageT"+id).innerHTML='<input class="textInput" style="vertical-align:middle" id="messageEditTitle'+id+'">';
dgi("messageEditTitle"+id).value=ih;
var w=100;
while(dgi("messageEditTitle"+id).offsetWidth<h) {w+=5;dgi("messageEditTitle"+id).style.width=w+"px";}
if(!focus) dgi("messageEditTitle"+id).focus(); else dgi("messageEdit"+id).focus();
}
function goMsg(ts){
dgi("action").value='prevNext';
dgi("value").value=ts;
if(window.winUseWindows && document.forms.miscAction.target=="") winMe.setReloading();
document.forms['miscAction'].submit();
}
function goMsgs(sts,ets){
dgi("action").value='period';
dgi("value").value=sts;
dgi("value2").value=ets;
if(window.winUseWindows && document.forms.miscAction.target=="") winMe.setReloading();
document.forms['miscAction'].submit();
}
function resetDate(){
dgi("action").value='resetDate';
if(window.winUseWindows && document.forms.miscAction.target=="") winMe.setReloading();
document.forms['miscAction'].submit();
}
function sendComment(id){
if(document.forms['newComment'+id].newCommentAuthor.value.length==0 || document.forms['newComment'+id].newCommentBody.value.length==0 )
alert('<? echo cfCaptionJS('genFillFields');?>');
else
{
if(window.winUseWindows && document.forms['newComment'+id].target=="") winMe.setReloading();
document.forms['newComment'+id].submit();
}
}
function showNewComment(id){
dgi('comment'+id).align="left";
var ih='<form name="newComment'+id+'" method="post" enctype="multipart/form-data">';
ih+='<div style="padding-bottom:0.5em;"><?php echo cfCaption('genAuthor','');?><input class="textInput" type="text" name="newCommentAuthor" size="60" value="<?php echo htmlentities(cfUTF8Encode((cfUGetVar('pseudo'))?cfUGetVar('pseudo'):cfUGetVar('name')),ENT_QUOTES); ?>"></div>';
ih+='<div style="padding-bottom:0.5em;"><?php echo cfCaption('genEMail');?> <input class="textInput" type="text" name="newCommentEMail" size="60"></div>';
ih+='<div style="padding-bottom:0.5em;"><?php echo cfCaption('blogLink');?> <input class="textInput" type="text" name="newCommentLink" size="60"></div>';
ih+='<textarea cols="60" rows="5" wrap="virtual" name="newCommentBody" style="margin-bottom:0.5em;width:100%"></textarea><br/><?php
echo outButton(cfCaption('genValidate'),'javascript:sendComment(\'+id+\')',outIcon('edit'),false,false,false,false);
echo '<input type="hidden" name="resId" value="'.$_SESSION['activeResourceId'].'">';
?><input name="messageID" type="hidden" value="'+id+'"></form>';
dgi('comment'+id).innerHTML=ih;
}
function toggleCommentsDisplay(nb){
if(!nb){
if(sendData("displayComments="+(1-commentsDisplay),"<?php echo $_SERVER['PHP_SELF'];?>",false)==false) return;
var i=0;
commentsDisplay=1-commentsDisplay;
if(commentsDisplay==1) {
dgi('showCommentsBt').style.display="none";
dgi('hideCommentsBt').style.display="inline";
}
else{
dgi('showCommentsBt').style.display="inline";
dgi('hideCommentsBt').style.display="none";
}
while(dgi('commentsArea'+i)){
if(commentsDisplay==1) dgi('commentsArea'+i).style.display="inline"; else dgi('commentsArea'+i).style.display="none";
i++;
}
}
else{
if(dgi('commentsArea'+nb).style.display=="none") dgi('commentsArea'+nb).style.display="inline"; else dgi('commentsArea'+nb).style.display="none";
}
}
function collapseAll(){
sendData("unfoldPosts=false","<?php echo $_SERVER['PHP_SELF'];?>",false);
i=0; while(dgi('innerMsgDiv' + i)){if(!wl.isCollapsed('innerMsgDiv'+i)) wl.nodeCollapseFold('innerMsgDiv' + i,false);i++;}
dgi('unfoldAllBt').style.display="inline";
dgi('collapseAllBt').style.display="none";
}
function unfoldAll(){
sendData("unfoldPosts=true","<?php echo $_SERVER['PHP_SELF'];?>",false);
i=0; while(dgi('innerMsgDiv' + i)){if(wl.isCollapsed('innerMsgDiv'+i)) wl.nodeCollapseUnfold('innerMsgDiv' + i,false);i++;}
dgi('unfoldAllBt').style.display="none";
dgi('collapseAllBt').style.display="inline";
}
</script>
</head>
<form name="miscAction" action="index.php" enctype="multipart/form-data" method="POST" style="display:none;">
<input name="action" id="action" type="hidden">
<input name="value" id="value" type="hidden">
<input name="value2" id="value2" type="hidden">
<input name="value3" id="value3" type="hidden">
<input type="hidden" name="resId" value="<?php echo $_SESSION['activeResourceId']; ?>">
</form>
<?php
/*
***************************************************************************************************************************
* Display BLOG
***************************************************************************************************************************
*/
// if a non critical error message is present, display it in a javascript alert box
if(isset($errorMessage)) echo"<body onload=\"javascript:alert('".$errorMessage."');\">";
else echo "\n<body>\n";
/*
* Messages and comments Section
*/
$allMessages=getMessagesList(false,false); // Get an array with all blog's messages. This array is used for previous/next buttons and for history
echo '<div id="topDiv">';
echo '<table width="100%"><tr>';
echo '<td id="mainTable" style="vertical-align:top;" width="'.((cfIsWII())?'100%':'80%').'">';
outShadowBefore('100%');
echo outDivFrame('frame1');
// Toggle comments display button
$tmpButton='';
$tmpButton.=outButton('', 'javascript:unfoldAll(false)',outIcon('plusX2'),false,'unfoldAllBt',((cfRGetVar('unfoldPosts'))?'style="display:none"':''));
$tmpButton.=outButton('', 'javascript:collapseAll(false)',outIcon('minusX2'),false,'collapseAllBt',((cfRGetVar('unfoldPosts'))? '': 'style="display:none"'));
if(cfRGetVar('commentsAllowed')) {
$tmpButton.=outButton(cfcaption('blogCommentsShow'), 'javascript:toggleCommentsDisplay(false)',false,false,'showCommentsBt',((cfRGetVar('displayComments'))? 'style="display:none"':''),false);
$tmpButton.=outButton(cfcaption('blogCommentsHide'), 'javascript:toggleCommentsDisplay(false)',false,false,'hideCommentsBt',((cfRGetVar('displayComments'))? '': 'style="display:none"'),false);
}
else $tmpButton=false;
// Frame1Header
echo outFrameHeaderTable('frame1Header',cfUTF8Encode(cfRGetVar('name')),$tmpButton);
echo '<div style="position:relative; width:400px;height:0px;"></div>'; // = min-width...
if($minMax || cfUGetVar('administrator')){
$tableDisplayed=false;
// New message button & form
if(cfUGetVar('administrator')){
echo outTableTransparent('frame1',"margin-bottom:0.5em;").'<tr><td style="text-align:left" width="50%">';
$tableDisplayed=true;
// "Post new message" button
echo '<span id="newPostButton">'.outButton(cfCaption('blogPostNewMessage'),'javascript:showNewMsg()',outicon('edit')).'</span>';
echo '</td>';
}
// "Next messages" button
if($minMax){
reset($messages); // position on first (most recent) of displayed messages
if(getTimeStamp(current($messages)->getAttribute('date'))<$minMax['max']){ // If this message is not the most recent
if(!$tableDisplayed){
echo outTableTransparent('frame1',"margin-bottom:0.5em;").'<tr>';
$tableDisplayed=true;
}
echo '<td style="text-align:right">';
// Find this message in entire messages list.
reset($allMessages); for($i=0;$i<count($allMessages);$i++) {if(current($allMessages)->getAttribute('date')==current($messages)->getAttribute('date')) break; next($allMessages);}
// Move maxPostPerPage steps backward
for($i=0;$i<cfRGetVar('maxPostPerPage');$i++) @prev($allMessages); if(!current($allMessages)) reset($allMessages);
$nextTS=getTimeStamp(current($allMessages)->getAttribute('date'));
// Display button
echo '<span style="width:50%;text-align:right;">'.outButton(cfCaption('blogNextPosts'),'javascript:goMsg('.$nextTS.')',outIcon('up'),cfCaption('blogNextPosts')).'</span></td>';
}
}
if($tableDisplayed) echo "</tr></table>\n";
// New message form
if(cfUGetVar('administrator')){
echo '<span id="newPostForm" style="display:none;" class="frame2"><div class="frame2Header"><img alt="" src="'.outIcon('edit').'" style="vertical-align:middle; margin-right:1em;">'.cfCaption('blogPostNewMessage').'</div>';
echo '<form name="newMessage" method="post" enctype="multipart/form-data">';
// Title
echo '<div style="padding-bottom:0.5em;">'.cfCaption('genTitle').' <input class="textInput" type="text" name="newMessageTitle" size="80"></div>';
// Textarea
echo '<textarea cols="80" rows="7" name="newMessageBody" style="width:100%"></textarea>';
// resId
echo '<input type="hidden" name="resId" value="'.$_SESSION['activeResourceId'].'">';
echo '</form>';
// Insert image form
echo '<div class="frame3"><div class="frame3header">'.cfCaption('blogInsertImage').'</div>';
// Position of image in message
$extraInnerHTML=cfCaption('genPosition').' <input type="radio" name="position" value="top" checked><img src="imgTop.gif">';
$extraInnerHTML.='<input type="radio" name="position" value="bottom"><img src="imgBottom.gif"/>';
// Size of image in message
$extraInnerHTML.='<span style="padding-left:3em;padding-right:2em;">'.cfCaption('genSize').'<input type="radio" name="size" value="small" checked /><img src="'.outIcon('imgSmall').'" alt=""><input type="radio" name="size" value="medium" checked /><img src="'.outIcon('imgMedium').'"><input type="radio" name="size" value="big" /><img src="'.outIcon('imgBig').'"></span><br/>';
// Insert upload form
outUploadForm('40','uploadCompleted','none','*resourceDataDir*',$extraInnerHTML);
echo '<center>'.outButton(cfCaption('genSend'),'javascript:initUpload();',outIcon('ok'),false,'uploadFormSubmitButton')."</center>\n";
// Upload result message
echo'<div class="frame3Footer" id="uploadResult">'.cfCaption('blogNoImageSent').'</div></div>';
// Validate
echo '<br/><center>'.outButton(cfCaption('genValidate'),'javascript:sendNewMessage()',outIcon('edit'));
// Cancel
echo '<span style="margin-left:10em;"></span>'.outButton(cfCaption('genCancel'),'javascript:hideNewMsg()',outIcon('cancel')).'</center>';
echo '</span>';
}
}
/*
***************************************************************************************************************************
* Messages and comments
***************************************************************************************************************************
*/
$nbDisplayedMessages=0;
$nbCommentFrames=0;
$currentCommentFrames=-1;
if(!count($messages)) echo '<br/><br/><center>'.cfCaption('blogNoPost').'</center><br/><br/><br/>';
else foreach ($messages as $message){
if(cfRGetVar('maxPostPerPage') && cfRGetVar('maxPostPerPage') <= $nbDisplayedMessages) break; // Limit number of displayed messages
/*
* MESSAGE
*/
// Message frame
echo outDivFrame('frame2');
// Delete message button
if(cfUGetVar('administrator')) {
$tmpLeft=outButton('','javascript:deleteMsg('.$message->getAttribute('ID').')',outIcon('cancel'),cfCaption('genDelete'),'supprBt'.$message->getAttribute('ID'),'style="margin-right:3px;"');
$tmpLeft.=outButton('','javascript:saveEditMsg('.$message->getAttribute('ID').')',outIcon('save'),cfCaption('genSave'),'saveBt'.$message->getAttribute('ID'),'style="margin-right:3px;display:none"');
$tmpLeft.='<span id="messageT'.$message->getAttribute('ID').'" onclick="javascript:editMsg('.$message->getAttribute('ID').',0)" style="cursor:pointer">';
}
else $tmpLeft=' ';
// Message title
$tmpLeft.=($message->getElementsByTagname('title')->item(0)->nodeValue);
if(cfUGetVar('administrator')) $tmpLeft.='</span>';
// Message collapse button
$tmpRight=outButtonToggleCollapse('innerMsgDiv'.$nbDisplayedMessages,false,cfRGetVar('unfoldPosts'));
echo outFrameHeaderTable('frame2Header',$tmpLeft, $tmpRight);
// Collapsing post frame
echo outCollapsableFrame('innerMsgDiv'.$nbDisplayedMessages,'unfoldPosts');
// Top image
$body=$message->getElementsByTagname('body')->item(0);
$image=$message->getElementsByTagname('image');
if($image->length && $image->item(0)->hasAttribute('position') && $image->item(0)->hasAttribute('fileName') && $image->item(0)->getAttribute('position')=='top') echo '<center>'.outImage(cfAppResourceDir().'/'.$image->item(0)->getAttribute('fileName')).'</center>';
// Message body
if(cfUGetVar('administrator'))
echo '<span id="message'.$message->getAttribute('ID').'" onclick="javascript:editMsg('.$message->getAttribute('ID').',1)" style="cursor:pointer; width:99%; position:relative">'.$body->nodeValue.'</span>';
else
echo '<span id="message'.$message->getAttribute('ID').'" style="width:99%; position:relative">'.$body->nodeValue.'</span>';
// Bottom image
if($image->length && $image->item(0)->hasAttribute('position') && $image->item(0)->hasAttribute('fileName') && $image->item(0)->getAttribute('position')=='bottom') echo '<center>'.outImage(cfAppResourceDir().'/'.$image->item(0)->getAttribute('fileName')).'</center>';
echo '<br/><br/>';
/*
* COMMENTS
*/
if(cfRGetVar('commentsAllowed')){
// Comment div, hidden or shown by toggleCommentsDisplay script
echo outCollapsableFrame('commentsArea'.$nbCommentFrames,'displayComments');
$currentCommentFrames=$nbCommentFrames; $nbCommentFrames++;
foreach (getCommentsList($message) as $ts=>$comment){
echo '<div class="frame3">';
// Comment header
echo '<div class="frame3header">'.cfCaption('blogCommentTitle',$comment['author']);
if(isset($comment['eMail']) || isset($comment['link']) || cfUGetVar('administrator')) {
echo ' (';
if(isset($comment['eMail'])) echo outMailSafe($comment['eMail']);
if(isset($comment['link'])) {
if(strtolower(substr($comment['link'],0,4))!='http') $link='http://'.$comment['link']; else $link=$comment['link'];
echo ((isset($comment['eMail'])?' / ':'').'<a href="'.$link.'" target="_blank">'.cfUTF8Encode($comment['link']).'</a>');
}
if(isset($comment['IP']) && cfUGetVar('administrator')) echo (isset($comment['eMail']) || isset($comment['link'])?' / ':'').'<a href="http://'.$comment['IP'].'" target="_blank">'.$comment['IP'].'</a>';
echo ')';
}
echo "</div>\n";
// Comment body
echo $comment['body'];
// Delete comment button
if(cfUGetVar('administrator'))
echo '<div align="right">'.outButton(cfCaption('genDelete'),'javascript:deleteMsg('.$comment['ID'].')',outIcon('cancel')).'</div>';
echo '<div class="frame3Footer">'.cfUTF8Encode(date(cfCaption('blogPostedDateFormat'), $ts)).'</div>';
echo '</div><br/>';
}
echo '</div>';
}
// Add comment button
if(cfRGetVar('commentsAllowed')) {
$tempRight=outButton(cfCaption('blogAddComment'),'javascript:showNewComment('.$message->getAttribute('ID').')','balloon.png');
echo '<span id="comment'.$message->getAttribute('ID').'"></span>';
}
else $tempRight=' ';
// Message footer
// Message date
$tempLeft=cfCaption('blogPosted',cfUTF8Encode(date(cfCaption('blogPostedDateFormat'), getTimeStamp($message->getAttribute('date')))));
if($message->hasAttribute('editDate')) $tempLeft.=', '.cfCaption('blogEdited',cfUTF8Encode(date(cfCaption('blogPostedDateFormat'), ($message->getAttribute('editDate')))));
if(cfRGetVar('commentsAllowed')){
// Number of comments
if($currentCommentFrames!=-1 && count(getCommentsList($message))) $tempLeft.= '<a href="javascript:toggleCommentsDisplay('.$currentCommentFrames.')" style="margin-left:3em;text-decoration:underline">'.((cfRGetVar('commentsAllowed'))?cfCaption('blogComments',count(getCommentsList($message))):'').'</a>';
else $tempLeft.= '<span style="margin-left:3em">'.((cfRGetVar('commentsAllowed'))?cfCaption('blogComments',count(getCommentsList($message))):'').'</span>';
$currentCommentFrames=-1;
}
// Display footer
echo outFrameFooterTable('frame2footer', $tempLeft, $tempRight);
echo "</div></div>\n";
$nbDisplayedMessages++;
}
// "Previous messages" button
if($minMax){
reset($messages); for($i=1;$i<cfRGetVar('maxPostPerPage');$i++) @next($messages); // Position on last (oldest) message
if(!current($messages)) end($messages); // If $messages contains less than maxPostPerPage, go to last message
if(getTimeStamp(current($messages)->getAttribute('date'))>$minMax['min']){ // If this message is not the most recent
// Find this message in entire messages list.
reset($allMessages);
for($i=0;$i<count($allMessages);$i++) {
if(current($allMessages)->getAttribute('date')==current($messages)->getAttribute('date')) break;
next($allMessages);
}
@next($allMessages); // Move one step forward
$previousTS=getTimeStamp(current($allMessages)->getAttribute('date'));
// Display button
echo '<div align="right">'.outButton(cfCaption('blogPreviousPosts'),'javascript:goMsg('.$previousTS.')',outIcon('down'),cfCaption('blogPreviousPosts')).'</div>';
}
}
echo '</div>';
outFrameShadowAfter();
echo "</td>\n";
/*
***************************************************************************************************************************
* RIGHT FRAME
***************************************************************************************************************************
*/
echo '<td id="profileTable" width="20%" '.((cfIsWII())?'style="position:absolute;width:0;overflow:hidden;vertical-align:top;"':'style="vertical-align:top;"').' class="vBanner">';
/*
* Profile Section
*/
if(cfRGetVar('useProfile')) {
outShadowBefore('100%');
echo outDivFrame('frame1');
echo outFrameHeaderTable('frame1header',outImage('profile.png',false,false, 'margin-right:1em;vertical-align:middle'),cfCaption('blogProfile'));
if(cfRGetVar('profileName')) echo '<div class="bigFont">'.cfUTF8Encode(cfRGetVar('profileName')).'<br/><br/></div>'; // Profile name
if(cfRGetVar('profileEMail')) echo outMailSafe(cfRGetVar('profileEMail')).'<br/><br/>'; // Profile e-mail
if(cfRGetVar('profileComment')) echo '<div>'.cfUTF8Encode(cfRGetVar('profileComment')).'</div>'; // Profile comment
echo "<br></div>\n";
outFrameShadowAfter();
echo "<br/>\n";
}
/*
* History
*/
outShadowBefore('100%');
echo outDivFrame('frame1');
echo outFrameHeaderTable('frame1header',outImage('calendar.png',false,false, 'margin-right:1em;vertical-align:middle'),cfCaption('blogPreviousPosts'));
@setlocale(LC_TIME , cfCaption('_ISO_639'));
// Display calendar of current month
$firstDayOfMonth=mktime(0,0,1,date('n'),1,date('Y'));
$day=$firstDayOfMonth; while (date('w',$day)!=1) $day+=3600*24;
$offset=(date('w',$firstDayOfMonth)==0)?7:date('w',$firstDayOfMonth);
echo '<center>';
// Current month
echo outButton(cfUTF8Encode(ucfirst(strftime('%B %Y',$firstDayOfMonth))),'javascript:resetDate()',false,false,false,'style="width:12em;"');
// Calendar header
echo '<table class="frame3" style="text-align:center;table-layout:fixed" cellspacing="0" cellpadding="0"><tr class="frame3header">';
for($i=0;$i<7;$i++) {echo '<td style="width:20px">'.cfUTF8Encode(strtoupper(substr(strftime('%A',$day),0,1))).'</td>'; $day+=3600*24;}
echo '</tr><tr class="bsRow">';
// Calendar body (days)
$day=$firstDayOfMonth;
for($i=1;$i<$offset;$i++) echo '<td> </td>';
$position=$offset-1;
for($i=1;$i<date('t',$firstDayOfMonth)+1;$i++){
if($position==7) {$position=0; echo '</tr><tr class="bsRow">';}
$position++;
if(messageInInterval(mktime(23,59,59,date('n',$firstDayOfMonth),$i,date('Y',$firstDayOfMonth)),mktime(0,0,1,date('n',$firstDayOfMonth),$i,date('Y',$firstDayOfMonth)))){
echo '<td class="buttonSmall" onclick="goMsgs(\''.mktime(0,0,1,date('n',$firstDayOfMonth),$i,date('Y',$firstDayOfMonth)).'\',\''.mktime(23,59,59,date('n',$firstDayOfMonth),$i,date('Y',$firstDayOfMonth)).'\')">'.$i.'</td>';
}
else echo '<td class="buttonSmallDisabled">'.$i.'</td>';
}
echo '</tr></table><br/>';
// Older messages (previous month)
$lastDisplayedMonth=mktime(0,0,1,date('n',$firstDayOfMonth),1,date('Y',$firstDayOfMonth));
foreach ($allMessages as $key=>$value){
$currentMonth=mktime(0,0,1,date('n',$key),1,date('Y',$key));
if($currentMonth<$lastDisplayedMonth){
echo outButton(cfUTF8Encode(ucfirst(strftime('%B %Y',$currentMonth))),'javascript:goMsgs('.$currentMonth.','.mktime(23,59,59,date('n',$currentMonth),date('t',$currentMonth),date('Y',$currentMonth)).')',false,false,false,'style="width:12em;"',true).'<br>';
$lastDisplayedMonth=$currentMonth;
}
}
echo '<br/></center></div>';
//messageInInterval
outFrameShadowAfter();
echo '</td></tr></table>';
outKeysManager();
?>
<script type="text/javascript">
var profileTableShown=false;
function optionKeyPressed(){
if(!profileTableShown) {
dgi("profileTable").style.position="relative";
dgi("mainTable").style.display="none";
profileTableShown=true;
}
else {
dgi("profileTable").style.position="absolute";
dgi("mainTable").style.display="inline";
profileTableShown=false;
}
}
<?php if(cfIsWII()) echo 'winMe.addIcon("option",optionKeyPressed,"'.outIcon('winOpt').'", "'.cfCaption('genOptions').'");'; ?>
</script>
</div>
</body>
</html>